React query handle 204 or zero content length#2235
Conversation
… returning data as null
❌ Deploy Preview for openapi-ts failed.
|
|
drwpow
left a comment
There was a problem hiding this comment.
Thank you! 204 responses are still tricky for folks, and agree this is better behavior.
Sorry for the delay in reviewing. But if you add a patch changeset (see GitHub comment), I‘d love to merge & release.
|
Going through open PRs, and I see this hasn’t had a changeset added. I’ll add one manually so we can release this. Thank you! |
* Update schema-object.ts * chore(deps): update dependency msw to v2.7.6 (openapi-ts#2287) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency @types/node to v22.15.10 (openapi-ts#2293) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency @shikijs/vitepress-twoslash to v3.4.0 (openapi-ts#2298) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency @arethetypeswrong/cli to ^0.18.0 (openapi-ts#2272) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency execa to v9.5.3 (openapi-ts#2303) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * fix(metadata): fix thunk type detection (openapi-ts#2125) * Don't remove `null` type if a default is present. (openapi-ts#2145) * Don't remove `null` type if a default is present. * Don't remove `null` type from enums if default is present. * Don't remove `null` type if default is present (legacy) * [ci] release (openapi-ts#2307) * [ci] release * Add 2145 manually --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Drew Powers <[email protected]> * chore(deps): update dependency @types/react to v18.3.21 (openapi-ts#2218) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * fix(openapi-fetch): fix overriding baseUrl per request without overriding default baseUrl (openapi-ts#2157) * Support $ref into `paths` (openapi-ts#2185) * React query handle 204 or zero content length (openapi-ts#2235) * fix(openapi-react-query): Handle 204 or zero Content-Length header by returning data as null * fix(openapi-react-query): updated and added 204 & zero Content-Length queryFn tests * chore(openapi-react-query): Fixed linting in test * chore(deps): update dependency @arethetypeswrong/cli to v0.18.1 (openapi-ts#2306) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency msw to v2.8.2 (openapi-ts#2304) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Update Speakeasy URL (openapi-ts#2302) * chore(deps): update dependency @tanstack/react-query to v5.75.7 (openapi-ts#2301) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * chore(deps): update dependency lint-staged to v15.5.2 (openapi-ts#2297) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * feat(swr-openapi): add custom error types to query builder (openapi-ts#2147) * chore(deps): update vitest monorepo to v3 (openapi-ts#2284) Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> * Encode the request body if Content-Type set (openapi-ts#2096) * Improve header handling (openapi-ts#2308) * [ci] release (openapi-ts#2309) * [ci] release * Release additional packages --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Drew Powers <[email protected]> * chore: update openapi-fetch test fixture (openapi-ts#2313) * Build packages with unbuild to improve CJS support (openapi-ts#2310) * [ci] release (openapi-ts#2314) * [ci] release * Fix major bump --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Drew Powers <[email protected]> * Update code of conduct source (openapi-ts#2316) Signed-off-by: Emmanuel Ferdman <[email protected]> --------- Signed-off-by: Emmanuel Ferdman <[email protected]> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Martin Paucot <[email protected]> Co-authored-by: Theron Luhn <[email protected]> Co-authored-by: openapi-ts-bot <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Drew Powers <[email protected]> Co-authored-by: Luis Merino <[email protected]> Co-authored-by: Duncan Beevers <[email protected]> Co-authored-by: Wheelebin <[email protected]> Co-authored-by: Nolan Di Mare Sullivan <[email protected]> Co-authored-by: しゅーまい <[email protected]> Co-authored-by: Olga Bulat <[email protected]> Co-authored-by: Emmanuel Ferdman <[email protected]>
Changes
I created an issue about how 204 status codes are handled and an error that's thrown by react-query due to data being returned as undefined (Something that react-query does not support for it's queryFn's).
Issue: #2234
This PR handles 204 or zero Content-Length header by returning data as null in the queryFn.
How to Review
Use the useQuery hook towards an API endpoint that returns a 204 status or zero value in the Content-Length header, the data should be set to null and no error should be thrown.
Checklist
docs/updated (if necessary)pnpm run update:examplesrun (only applicable for openapi-typescript)